export default{
	data(){
		return {
			modal1:false,
			list:[],//列表
			selection:[],
			formValidate:{
                	title: '',
                    author:'',
                    content:''
                },
			filter:{
				page:1,
				limit:2,
				name:"",
				total:0
			},
            ruleValidate: {
                title: [
                    { required: true, message: '标题不能为空', trigger: 'blur' }
                ],
                author: [
                    { required: true, message: '作者不能为空', trigger: 'blur' }
                ],
                Games: [
                    { required: true, message: '副标题不能为空', trigger: 'blur' },
                ],
                content: [
                    { required: true, message: '内容不能为空', trigger: 'blur' },
                ]
                
            },
			columns7: [
                	{
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        title: '标题',
                        key: 'title',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.title)
                            ]);
                        }
                    },
                    {
                        title: '作者',
                        key: 'author'
                    },
                    {
                        title: '副标题',
                        key: 'Games'
                    },
                    {
                        title: '内容',
                        key: 'content'
                    },
                    {
                        title: '时间',
                        key: 'data'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        width:180,
                        render: (h, params) => {
                            return h('div', [  
	                            h('Button', {
	                                    props: {
	                                        type: 'primary',
	                                        size: 'small',
	              
	                                    },
	                                    style: {
	                                    	marginRight: '5px'
	                                    },
	                                    on: {
	                                        click: () => {
//	                                            location.href="http://localhost:8080/#/comment"
//												this.$router.push({path:'/comment'});
//												this.skip(params.row._id)
												this.$router.push({path:'/comment/'+params.row._id})
	                                        }
	                                    }
	                                }, '查看'),
                                h('Button', {
                                    props: {
                                        type: 'success',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px'
                                    },
                                    on: {
                                        click: () => {
                                            this.editData(params.row._id)
                                        }
                                    }
                                }, '编辑'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row._id,params.index)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ]
		}
	},
	methods:{
		remove (id,index) {
        	this.$http({
        		method:'delete',
        		url:`http://localhost:3000/${this.module}/data/`+id,	        		
        	}).then((response)=>{
        		this.getData();
        	})             
        },
		onPageSizeChange(pageSize){
			this.filter.limit=pageSize;
			this.getData();
		},
		handleSelectAll (status) {			
            this.$refs.selection.selectAll(status);
        },
        changePage(page){
			this.filter.page=page;
			this.getData();
		},
		getarr(){
			this.ids.forEach((element)=>{ 
				var arr=element._id;
				this.getsDatas(arr)	
			})
		},
		editData (id) {
			this.$http({
				method:"GET",
				url:`http://localhost:3000/${this.module}/data/`+id,
			}).then((response)=>{			
				this.formValidate=response.data;
        	})
            this.modal1=true;
		},
		getsDatas(ids){
			this.$http({
				method:"POST",
				url:`http://localhost:3000/${this.module}/list`,
				data:{
					cateId:ids
				},
			}).then(res=>{
				this.list=res.data.rows;
				this.filter.total=res.data.total;
			})
		},
		getData(){	
			this.$http({
				method:"POST",
				url:`http://localhost:3000/${this.module}/list`,
				data:this.filter,
			})
			.then(res=>{
				this.list=res.data.rows;
				this.filter.total=res.data.total;				
			})
		},
		removeSelectAll(){
        	this.selection.forEach((element)=>{       	
        		this.$http({
	        		method:'delete',
	        		url:`http://localhost:3000/${this.module}/data/`+element._id,	        		
	        	}).then((response)=>{
	        		console.log(response)
	        		this.getData();
	        	})	        	
        	})       	
        },
        search(){
        	this.getData();
        },
        removeSelect(selection){
       		this.selection=selection;
        },
	},
	created(){
		this.getData();
	}
}